package com.company.test30;

import javax.swing.*;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * Created by v on 16-12-1.
 */
public class Test30_06 extends JApplet {
    private JLabel jlblCOunt=new JLabel();

    private boolean isStandAlone=false;

    private String host="localhost";

    public void init(){
        add(jlblCOunt);

        try{
            Socket socket;
            if(isStandAlone)
                socket=new Socket(host,8000);
            else
                socket=new Socket(getCodeBase().getHost(),8000);

            DataInputStream inputFromServr=
                    new DataInputStream(socket.getInputStream());

            int count=inputFromServr.readInt();
            jlblCOunt.setText("You are visitor number "+count);

            inputFromServr.close();
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
}
